# @Author : DGGem
# @Email : 1254656865@qq.com
# @Project : hids
# @脚本说明 : 用户自定义规则
from app.models.mongo_model import mongo_conn

mon = mongo_conn()  # 连接mongodb
collection = mon['custom']  # 指定集合


def get_user_defined(details, level, words):
    details = details  # 描述
    level = level  # 等级
    words = words.split(',')  # 关键字，以逗号分割成列表
    if details == "sql注入":
        title = "sql_inject"
    elif details == "xss攻击":
        title = "xss_attack"
    else:
        title = "other"
    cus = {
        title: {
            "details": details,
            "Level": level,
            "words": words
        }
    }
    collection.insert_one(cus)  # 写入mongodb
    find_result = collection.find_one(cus)
    print(find_result, "你的自定义规则以写入数据库")
